<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;

class HikangController extends Controller
{
    public function car(){
        //获取accesstoken
        $apiurl = 'https://open.ys7.com/api/lapp/token/get';
        $data['appKey'] = '74d0e2047e784a28915cdc26e9f1f909';
        $data['appSecret'] = 'ff7cc0a81c1f6d6ac2051461c80c3d6c';
        $res = $this->curl_post($apiurl,$data);
        $acce = json_decode($res,1);
        $accesstoken = $acce['data']['accessToken'];
        //关闭视频加密
        $url = 'https://open.ys7.com/api/lapp/device/encrypt/off';
        $data1['accessToken'] = $acce['data']['accessToken'];
        $data1['deviceSerial'] = 'D40096405';
        $data1['validateCode'] = 'HK123456';
        $res = $this->curl_post($url,$data1);
        return view('/car',['accesstoken' => $accesstoken]);
        //return $accesstoken;
    }
    public function curl_post($url , $data=array()){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        // POST数据
        curl_setopt($ch, CURLOPT_POST, 1);
        // 把post的变量加上
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
}